<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="google-site-verification" content="xBT4GhYoi5qRD5tr338pgPM5OWHHIDR6mNg1a3euekI" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="智红的博客">
    <meta name="keyword"  content="智红">
    <link rel="shortcut icon" href="/img/favicon.ico">

    <title>
        
        vim - 智红的博客
        
    </title>

    <!-- Custom CSS -->
    
<link rel="stylesheet" href="/css/aircloud.css">

    
<link rel="stylesheet" href="/css/gitment.css">

    <!--<link rel="stylesheet" href="https://imsun.github.io/gitment/style/default.css">-->
    <link href="//at.alicdn.com/t/font_620856_pl6z7sid89qkt9.css" rel="stylesheet" type="text/css">
    <!-- ga & ba script hoook -->
    <script></script>
<meta name="generator" content="Hexo 5.3.0"></head>

<body>

<div class="site-nav-toggle" id="site-nav-toggle">
    <button>
        <span class="btn-bar"></span>
        <span class="btn-bar"></span>
        <span class="btn-bar"></span>
    </button>
</div>

<div class="index-about">
    <i> 好记性不如烂键盘呐 </i>
</div>

<div class="index-container">
    
    <div class="index-left">
        
<div class="nav" id="nav">
    <div class="avatar-name">
        <div class="avatar ">
            <img src="/img/avatar.jpg" />
        </div>
        <div class="name">
            <i>Zhihong Li</i>
        </div>
    </div>
    <div class="contents" id="nav-content">
        <ul>
            <li >
                <a href="/">
                    <i class="iconfont icon-shouye1"></i>
                    <span>主页</span>
                </a>
            </li>
            <li >
                <a href="/tags">
                    <i class="iconfont icon-biaoqian1"></i>
                    <span>标签</span>
                </a>
            </li>
            <li >
                <a href="/archive">
                    <i class="iconfont icon-guidang2"></i>
                    <span>存档</span>
                </a>
            </li>
            <li >
                <a href="/about/">
                    <i class="iconfont icon-guanyu2"></i>
                    <span>关于</span>
                </a>
            </li>
            
            <li>
                <a id="search">
                    <i class="iconfont icon-sousuo1"></i>
                    <span>搜索</span>
                </a>
            </li>
            
        </ul>
    </div>
    
        <div id="toc" class="toc-article">
    <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#vim%E5%B0%8F%E6%8A%80%E5%B7%A7"><span class="toc-text">vim小技巧</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%BF%AB%E9%80%9F%E6%8F%92%E5%85%A5%E6%97%B6%E9%97%B4"><span class="toc-text">快速插入时间</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%A4%8D%E5%88%B6-%E5%89%AA%E5%88%87-%E5%88%A0%E9%99%A4"><span class="toc-text">复制&#x2F;剪切&#x2F;删除</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#vim%E5%AF%84%E5%AD%98%E5%99%A8"><span class="toc-text">vim寄存器</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%B2%98%E8%B4%B4%E7%BD%91%E4%B8%8A%E6%8B%B7%E8%B4%9D%E7%9A%84%E4%BB%A3%E7%A0%81%E5%87%BA%E7%8E%B0%E7%BC%A9%E8%BF%9B%E5%AF%B9%E9%BD%90%E9%94%99%E4%B9%B1"><span class="toc-text">粘贴网上拷贝的代码出现缩进对齐错乱</span></a></li></ol></li></ol>
</div>
    
</div>


<div class="search-field" id="search-field">
    <div class="search-container">
        <div class="search-input">
            <span id="esc-search"> <i class="icon-fanhui iconfont"></i></span>
            <input id="search-input"/>
            <span id="begin-search">搜索</span>
        </div>
        <div class="search-result-container" id="search-result-container">

        </div>
    </div>
</div>

        <div class="index-about-mobile">
            <i> 好记性不如烂键盘呐 </i>
        </div>
    </div>
    
    <div class="index-middle">
        <!-- Main Content -->
        


<div class="post-container">
    <div class="post-title">
        vim
    </div>

    <div class="post-meta">
        <span class="attr">发布于：<span>2019-10-26 15:32:41</span></span>
        
        <span class="attr">标签：/
        
        <a class="tag" href="/tags/#vim" title="vim">vim</a>
        <span>/</span>
        
        
        </span>
        <span class="attr">访问：<span id="busuanzi_value_page_pv"></span>
</span>
</span>
    </div>
    <div class="post-content no-indent">
        <h1 id="vim小技巧"><a href="#vim小技巧" class="headerlink" title="vim小技巧"></a>vim小技巧</h1><h2 id="快速插入时间"><a href="#快速插入时间" class="headerlink" title="快速插入时间"></a>快速插入时间</h2><p>把下面行追加到 ~/.vimrc ，在vim的插入模式输入 xtime 即可</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">iab xtime &lt;c-r&gt;=strftime(<span class="string">&quot;%Y-%m-%d %H:%M:%S&quot;</span>)&lt;cr&gt;</span><br></pre></td></tr></table></figure>
<h2 id="复制-剪切-删除"><a href="#复制-剪切-删除" class="headerlink" title="复制/剪切/删除"></a>复制/剪切/删除</h2><p><code>print("Hi, this is a 'word'!")</code></p>
<ul>
<li>拷贝<code>word</code>:光标移到<code>o</code>，<code>yiw</code>(举一反三:<code>viw</code>,<code>diw</code>,<code>ciw</code>)或者<code>yi'</code></li>
<li>拷贝<code>'word'</code>:光标移到<code>o</code>，<code>ya'</code>(举一反三:<code>va'</code>,<code>da'</code>,<code>ca'</code>)</li>
<li>拷贝<code>Hi, this is a 'word'!</code>:光标移到<code>o</code>，<code>yi"</code>(举一反三:<code>vi"</code>,<code>di"</code>,<code>ci"</code>)</li>
<li>拷贝<code>"Hi, this is a 'word'!"</code>:光标移到<code>o</code>，<code>ya"</code>(举一反三:<code>va"</code>,<code>da"</code>,<code>ca"</code>)</li>
</ul>
<h2 id="vim寄存器"><a href="#vim寄存器" class="headerlink" title="vim寄存器"></a>vim寄存器</h2><p>查看vim常用寄存器的保存的内容<code>:registers</code></p>
<p>a-z每个字母对应一个寄存器,查看寄存器a对应的值<code>:reg a</code>,查看寄存器b对应的值<code>:reg a</code></p>
<p><code>normal</code>模式下粘贴寄存器a的内容<code>"ap</code>,<code>insert</code>模式下粘贴寄存器a的内容<code>Ctrl+r a</code></p>
<p><code>print("Hi, this is a 'word'!")</code></p>
<ul>
<li>拷贝<code>word</code>进<code>寄存器a</code>:光标移到<code>o</code>,<code>"a</code>(选择<code>寄存器a</code>),<code>yiw</code>(拷贝单词)</li>
<li>拷贝<code>this</code>进<code>寄存器b</code>:光标移到<code>h</code>,<code>"b</code>(选择<code>寄存器b</code>),<code>yiw</code>(拷贝单词)</li>
<li>查看<code>寄存器a</code>保存的内容:<code>:reg a</code></li>
<li>查看<code>寄存器b</code>保存的内容:<code>:reg b</code></li>
<li>粘贴<code>word</code>(即<code>寄存器a</code>的内容):光标移到粘贴位置,<code>"a</code>(选择<code>寄存器a</code>),<code>p</code>(粘贴)</li>
<li>粘贴<code>this</code>(即<code>寄存器b</code>的内容):光标移到粘贴位置,<code>"b</code>(选择<code>寄存器b</code>),<code>p</code>(粘贴)</li>
</ul>
<p>当我们不选择寄存器直接使用<code>y</code>或<code>d</code>操作时，被操作的内容会被拷贝或者剪切到<code>""</code>(无名寄存器)中</p>
<p><code>"%</code>:内容是当前文件名，一般写文件注释头会用到</p>
<p><code>".</code>:上次插入的文本</p>
<p><code>"+</code>:系统剪切板,查看vim是否支持使用系统剪切板<code>:echo has('clipboard')</code>,输出1表示支持</p>
<ul>
<li>在别的程序(如浏览器网页)用鼠标选择内容,<code>Ctrl+c</code>(拷贝内容到系统剪切板),回到vim用<code>"+</code>(选择系统剪切板),<code>p</code>(粘贴系统剪切板的内容)</li>
<li><code>"+</code>(选择系统剪切板),<code>yy</code>(拷贝一行进入系统剪切板),可以在别的编辑器或者程序(如浏览器搜索框)里用<code>Ctrl+v</code>粘贴</li>
<li>vim拷贝默认放入<code>""</code>(无名寄存器),如果想用<code>"+</code>(系统剪切板)取代<code>""</code>(无名寄存器),需要<code>:set clipboard^=unnamed,unnamedplus</code></li>
</ul>
<h2 id="粘贴网上拷贝的代码出现缩进对齐错乱"><a href="#粘贴网上拷贝的代码出现缩进对齐错乱" class="headerlink" title="粘贴网上拷贝的代码出现缩进对齐错乱"></a>粘贴网上拷贝的代码出现缩进对齐错乱</h2><p>当vim <code>:set autoindent</code> 之后，在<code>insert</code>模式下用<code>Ctrl+Shift+v</code>粘贴网上拷贝的代码会出现缩进对齐错乱</p>
<ul>
<li>方法1. <code>:set paste</code>,<code>i</code>(进入插入模式),<code>Ctrl+Shift+v</code>(粘贴),<code>:set nopaste</code></li>
<li>方法2. <code>"+</code>(选择系统剪切板),<code>p</code>(粘贴)</li>
<li>方法3. <code>:set clipboard^=unnamed,unnamedplus</code>(使用系统剪切板取代无名寄存器),<code>p</code>(粘贴)</li>
</ul>

        
        <br />
        <div id="comment-container">
        </div>
        <div id="disqus_thread"></div>

        <div id="lv-container">
        </div>

    </div>
</div>

    </div>
</div>


<footer class="footer">
    <ul class="list-inline text-center">
        
        

        

        

        

        

    </ul>
    
    <p>
        <span id="busuanzi_container_site_pv">
            <span id="busuanzi_value_site_pv"></span>PV
        </span>
        <span id="busuanzi_container_site_uv">
            <span id="busuanzi_value_site_uv"></span>UV
        </span>
        Created By <a target="_blank" rel="noopener" href="https://hexo.io/">Hexo</a>  Theme <a target="_blank" rel="noopener" href="https://github.com/aircloud/hexo-theme-aircloud">AirCloud</a></p>
</footer>




</body>

<script>
    // We expose some of the variables needed by the front end
    window.hexo_search_path = "search.json"
    window.hexo_root = "/"
    window.isPost = true
</script>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>

<script src="/js/index.js"></script>

<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>




</html>
